﻿package mortal.game.view.copy.ChallengeCopy.newView
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import flash.text.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.copy.ChallengeCopy.data.*;
    import mortal.mvc.core.*;

    public class ChallengeInfoPanel extends GSprite
    {
        private var _challengeData:ChallengeData;
        private var _mapPart:ChallengeMapPart;
        private var _bg:GImageBitmap;
        private var _enterCopyBtn:GLoadingButton;
        private var _timeClearBtn:GLoadedButton;
        private var _leftTime:SecTimerView;
        private var _leftTimeTxt:GTextFiled;
        private var _combat:BitmapNumberText;

        public function ChallengeInfoPanel()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.gImageBitmap("", 0, 0, this);
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.ChallengeNewSugCombatBg, 155, 507 + 37, this));
            this._combat = UIFactory.bitmapNumberText(240, 510 + 37, "SignUpNum2.png", 22, 23, -6, this);
            this._enterCopyBtn = UIFactory.gLoadingButton(ResFileConst.tower_win_go2, 352, 505 + 37, 157, 39, this);
            this._enterCopyBtn.configEventListener(MouseEvent.CLICK, this.onMouseClick);
            this._leftTimeTxt = UIFactory.gTextField(Language.getString(35112), 358, 528 + 37, 100, 20, this);
            this._leftTime = UIFactory.secTimeView(Language.getString(30055), 420, 528 + 37, 0, 0, this, GlobalStyle.textFormatLv);
            this._leftTime.filters = [FilterConst.glowFilter];
            this._leftTime.autoSize = TextFieldAutoSize.LEFT;
            this._leftTime.setParse(Language.getString(30056));
            this._leftTime.configEventListener(EventName.SecViewTimeChange, this.onSecViewTimeChangeHandler);
            this._timeClearBtn = UIFactory.gLoadedButton(ImagesConst.FashionExpandBtn_upSkin, 485, 527 + 37, 24, 25, this);
            this._timeClearBtn.configEventListener(MouseEvent.CLICK, this.timeClearHandler);
            this._mapPart = UICompomentPool.getUICompoment(ChallengeMapPart);
            this._mapPart.y = 37;
            this.addChild(this._mapPart);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._bg.dispose(param1);
            this._bg = null;
            this._combat.dispose(param1);
            this._combat = null;
            this._enterCopyBtn.dispose(param1);
            this._enterCopyBtn = null;
            this._timeClearBtn.dispose(param1);
            this._timeClearBtn = null;
            this._leftTime.dispose(param1);
            this._leftTime = null;
            this._leftTimeTxt.dispose(param1);
            this._leftTimeTxt = null;
            this._mapPart.dispose(param1);
            this._mapPart = null;
            this._challengeData = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function onSecViewTimeChangeHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data as int;
            if (_loc_2 == 0)
            {
                if (this.contains(this._leftTime))
                {
                    this.removeChild(this._leftTime);
                }
                if (this.contains(this._timeClearBtn))
                {
                    this.removeChild(this._timeClearBtn);
                }
                if (this.contains(this._leftTimeTxt))
                {
                    this.removeChild(this._leftTimeTxt);
                }
                Cache.instance.copy.challengCopy.residuettimes = 0;
                this._enterCopyBtn.y = 505 + 37;
            }
            else
            {
                this._enterCopyBtn.y = 491 + 37;
            }
            return;
        }// end function

        private function timeClearHandler(event:MouseEvent) : void
        {
            var _loc_2:Object = {code:GameConst.ChallengeCopyCode, leftTime:this._leftTime.getLeftTime()};
            Dispatcher.dispatchEvent(new DataEvent(EventName.ChallengeClearCD, _loc_2));
            return;
        }// end function

        private function onMouseClick(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.ChallengCopyEnter, this._challengeData));
            return;
        }// end function

        public function set data(param1:ChallengeData) : void
        {
            var _loc_2:TChallengeCopy = null;
            var _loc_3:Boolean = false;
            this._challengeData = param1;
            this._bg.imgUrl = "";
            if (this._challengeData)
            {
                _loc_2 = ChallengeCopyConfig.instance.getDataByTowerAndSectionAndDif(this._challengeData.tChallengCopy.tower, this._challengeData.tChallengCopy.section, (this._challengeData.passLevel + 1));
                if (_loc_2)
                {
                    this._combat.text = _loc_2.sugCombat.toString();
                }
                else
                {
                    this._combat.text = "0";
                }
                this._bg.imgUrl = "ExpeditionMap_" + ChallengeUtil.getSectionUrlByTChallenge(this._challengeData.tChallengCopy, "jpg");
                _loc_3 = ChallengeUtil.isCanEnterStateByTChallenge(this._challengeData.tChallengCopy) == 0;
                if (_loc_3)
                {
                    this._enterCopyBtn.enabled = true;
                    this._enterCopyBtn.filters = [];
                }
                else
                {
                    this._enterCopyBtn.enabled = false;
                    this._enterCopyBtn.filters = [FilterConst.colorFilter2];
                }
                this._mapPart.data = this._challengeData;
            }
            return;
        }// end function

        public function updateRecord(param1:SChallengeCopyRecords) : void
        {
            return;
        }// end function

        public function updateLeftTime() : void
        {
            var _loc_1:* = Cache.instance.copy.challengCopy.residuettimes;
            if (_loc_1 > 0)
            {
                if (_loc_1 > 3600)
                {
                    this._leftTime.setParse(Language.getString(30055));
                }
                else if (_loc_1 < 3600)
                {
                    this._leftTime.setParse(Language.getString(30056));
                }
                this.addChild(this._leftTime);
                this.addChild(this._timeClearBtn);
                this.addChild(this._leftTimeTxt);
            }
            this._leftTime.setLeftTime(_loc_1);
            return;
        }// end function

        public function get mapPart() : GSprite
        {
            return this._mapPart.mapPart;
        }// end function

    }
}
